package com.xjgzinfo.usdp.service.impl;

import com.xjgzinfo.usdp.domain.BladeVisualRecord;
import com.xjgzinfo.usdp.repository.BladeVisualRecordRepository;
import com.xjgzinfo.usdp.service.BladeVisualRecordService;
import com.xjgzinfo.usdp.service.dto.BladeVisualRecordDTO;
import com.xjgzinfo.usdp.service.mapper.BladeVisualRecordMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * Service Implementation for managing {@link BladeVisualRecord}.
 */
@Service
@Transactional
public class BladeVisualRecordServiceImpl implements BladeVisualRecordService {

    private final Logger log = LoggerFactory.getLogger(BladeVisualRecordServiceImpl.class);

    private final BladeVisualRecordRepository bladeVisualRecordRepository;

    private final BladeVisualRecordMapper bladeVisualRecordMapper;

    public BladeVisualRecordServiceImpl(BladeVisualRecordRepository bladeVisualRecordRepository, BladeVisualRecordMapper bladeVisualRecordMapper) {
        this.bladeVisualRecordRepository = bladeVisualRecordRepository;
        this.bladeVisualRecordMapper = bladeVisualRecordMapper;
    }

    @Override
    public BladeVisualRecordDTO save(BladeVisualRecordDTO bladeVisualRecordDTO) {
        log.debug("Request to save BladeVisualRecord : {}", bladeVisualRecordDTO);
        BladeVisualRecord bladeVisualRecord = bladeVisualRecordMapper.toEntity(bladeVisualRecordDTO);
        bladeVisualRecord = bladeVisualRecordRepository.save(bladeVisualRecord);
        return bladeVisualRecordMapper.toDto(bladeVisualRecord);
    }

    @Override
    @Transactional(readOnly = true)
    public Page<BladeVisualRecordDTO> findAll(Pageable pageable) {
        log.debug("Request to get all BladeVisualRecords");
        return bladeVisualRecordRepository.findAll(pageable)
                .map(bladeVisualRecordMapper::toDto);
    }


    @Override
    @Transactional(readOnly = true)
    public Optional<BladeVisualRecordDTO> findOne(Long id) {
        log.debug("Request to get BladeVisualRecord : {}", id);
        return bladeVisualRecordRepository.findById(id)
                .map(bladeVisualRecordMapper::toDto);
    }

    @Override
    public void delete(Long id) {
        log.debug("Request to delete BladeVisualRecord : {}", id);
        bladeVisualRecordRepository.deleteById(id);
    }
}
